package com.weng.bigdata.core.jdbc.constant;

/**
* JDBC数据库常量
* @author wengzhonghui
* @date: 2021-07-05 16:54:45
*/
public class JdbcConstants {

    /**
     * SQL类型为字符串的JDBC类型
     */
    private static String[] SQL_STRING_TYPES = new String[]{
            "CHAR", "NCHAR", "VARCHAR", "NVARCHAR", "LONGVARCHAR", "LONGNVARCHAR", "VARCHAR2", "NVARCHAR2",
            "STRING", "TINYTEXT", "TEXT", "NTEXT", "MEDIUMTEXT", "LONGTEXT",
            "JSON", "XML", "LINESTRING", "MULTILINESTRING",
            "TINYBLOB", "MEDIUMBLOB", "BLOB", "LONGBLOB", "CBLOB",
            "BINARY", "VARBINARY", "LONGVARBINARY", "ENUM", "SET", "NULL", "ROWID",
            "FIXEDSTRING", "IPV4", "IPV6", "UUID"
    };

    /**
     * SQL类型为字符类型的JDBC类型
     */
    private static String[] SQL_NUMBER_TYPES = new String[]{
            "BIT", "TINYINT", "SMALLINT", "MEDIUMINT", "INT", "INTEGER", "BIGINT",
            "FLOAT", "DOUBLE", "DOUBLE PRECISION", "REAL", "DECIMAL",
            "BIT", "SERIAL", "BOOL", "BOOLEAN", "DEC", "FIXED", "NUMBER", "NUMERIC",
            "UINT8", "UINT16", "UINT32", "UINT64", "INT8", "INT16", "INT32", "INT64",
            "FLOAT32", "FLOAT64", "DECIMAL32", "DECIMAL64", "DECIMAL128"
    };

    /**
     * SQL类型为时间类型的JDBC类型
     */
    private static String[] SQL_DATE_TYPES = new String[]{
            "DATE", "DATETIME", "TIMESTAMP", "TIME", "YEAR"
    };

    /**
     *  判断JDBC类型是否为时间类型
     * @param jdbcType
     * @return
     */
    public static boolean isDateType(String jdbcType){
        for(String type : SQL_DATE_TYPES){
            if(type.equalsIgnoreCase(jdbcType)){
                return true;
            }
        }
        return false;
    }

    /**
     *  判断JDBC类型是否为数值类型
     * @param jdbcType
     * @return
     */
    public static boolean isNumberType(String jdbcType){
        for(String type : SQL_NUMBER_TYPES){
            if(type.equalsIgnoreCase(jdbcType)){
                return true;
            }
        }
        return false;
    }

    /**
     *  判断JDBC类型是否为字符类型
     * @param jdbcType
     * @return
     */
    public static boolean isStringType(String jdbcType){
        for(String type : SQL_STRING_TYPES){
            if(type.equalsIgnoreCase(jdbcType)){
                return true;
            }
        }
        return false;
    }
}
